<?php
ob_start();
session_start();
include 'top3.php';
include("utils.php");
main_content("mainBuySpace();");
if(!isset($_SESSION[siteuserId]) ||  $_SESSION[siteuserId]=='')
	echo '<script>window.location="index.php"</script>';
function mainBuySpace()
{
if($_SESSION['langId']!="")
	{
		$langId=$_SESSION['langId'];
	}
	else
	{
		$langId="1";
	}
 $sql="select s.adSiteUrl,s.adSiteId,adm.*,addet.adspaceType,fav.favId FROM ".FAVADSPACE." as fav,".SITEMASTER." as s,".ADSPSCEMASTER." as adm,".ADSPACEDETAILS." as addet where s.langId='".$langId."' and fav.userId='".$_SESSION[siteuserId]."' and fav.adspaceId=adm.adspaceId  and s.adsiteId=adm.adsiteId and addet.adspaceId=adm.adspaceId order by fav.addedOn desc";

$query=mysql_query($sql);
//}

?>
<link rel="stylesheet" href="popup_js/style.css" type="text/css">
<link rel="stylesheet" href="popup_js/style_002.css" type="text/css">

<script type="text/javascript" language="javascript" src="popup_js/popup-layer.js"></script>
<script type="text/javascript" src="popup_js/popup-adspace.js"></script>
<script type="text/javascript" src="popup_js/popup-price.js"></script>
<script src="ajax/prototype.js"></script>
<script src="ajax/ajax.js"></script>
<script language="javascript" type="text/javascript">
<!--
          var delayTimeForMouseoverPopup = 500;

    var sid = 'f24dc7bb351fe6c1ed714721b1e632ff';
    var popUpLayer = new PopUpLayer(true);
    var randomNumber = null;
    var disableDisplay = window.onload;
    window.onload = function() {
        if (disableDisplay) {
            disableDisplay();
        }
                            resizePage();
        ;
    }

    function popUpPreview(id, e, layer) {
        randomNumber = Math.random();
        var element = PopUpLayer.getSrcElement(e);
        var position = PopUpLayer.getCoordinate(element);
        window.setTimeout(popUpImpl, delayTimeForMouseoverPopup, id, position, element, layer, randomNumber);
    }

    function popUpImpl(id, position, element, layer, number) {
        if (number != randomNumber) {
            return null;
        }
        if (layer == 'product') {
            popupSpace.show(id);
            popupSpace.adjustPopUpPosition(position, element);
        }
        else {
            popupPrice.show(id);
            popupPrice.adjustPopUpPosition(position, element);
        }
    }

    var _st = window.setTimeout;
    window.setTimeout = function(fRef, mDelay) {
        if(typeof fRef == 'function'){
            var argu = Array.prototype.slice.call(arguments,2);
            var f = (function(){ fRef.apply(null, argu); });
            return _st(f, mDelay);
        } 
        return _st(fRef,mDelay);
    }
    

    function hidePreview() {
        randomNumber = Math.random();
        if (true == popupSpace.isDisplay) {
            popupSpace.hide();
        }
        if (true == popupPrice.isDisplay) {
            popupPrice.hide();
        }
    }

    //Resize page when the control is wider than the table.
    function resizePage() {
        var width = document.getElementById("spaceListBlock").scrollWidth;
        document.getElementById("control").style.width = parseInt(width) + "px";
    }
-->

</script>
<script src="ajax/prototype.js"></script>
<script src="ajax/ajax.js"></script>

<script>
function deleteFromFav()
{
	if(document.getElementById('hidAdSpaceId').value=='')
		document.getElementById('errorId').innerHTML = '<div style="width:750px;height:40px;border:#999999 thin solid; vertical-align:middle;" class="err_class"><br>Please select a record by clicking on it.</div>';
	else
	{
		document.getElementById('errorId').innerHTML = '';
		deleteFromFavAjax('include_ajax/',document.getElementById('hidAdSpaceId').value);
	}
}
function addAdSpaceId(val,$count)
{
	hidID = document.getElementById('hidAdSpaceId').value;
	var valWithComma = val+',';
	if(hidID.search(val)==-1)
	{
		document.getElementById('hidAdSpaceId').value =valWithComma+document.getElementById('hidAdSpaceId').value;
		document.getElementById('trList'+val).className = 'normalActive';
	}
	else
	{
		document.getElementById('hidAdSpaceId').value =hidID.replace(valWithComma,'');
		if($count==0)
			document.getElementById('trList'+val).className = 'normal2';
		else
			document.getElementById('trList'+val).className = 'normal';
	}	
}
function checkClassName(val,$count)
{
hidID = document.getElementById('hidAdSpaceId').value;
	var valWithComma = val+',';
	if(hidID.search(val)==-1)
	{
		
		if($count==0)
			document.getElementById('trList'+val).className = 'normal2';
		else
			document.getElementById('trList'+val).className = 'normal';
	}
	else
	{
		if($count==0)
			document.getElementById('trList'+val).className = 'normalActive2';
		else
			document.getElementById('trList'+val).className = 'normalActive';
	}	
}
</script>
<input type="hidden" name="hidAdSpaceId" id="hidAdSpaceId" value=""><br />
<br />



<div id="control" style="width: auto; padding-top: 5px; padding-bottom: 15px;">

<table width="90%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td valign="top" align="center"><table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
                  <tr>
                    <td width="20%" valign="top"><?php include("left_pannel.php"); ?></td>
                    <td valign="top"><table width="98%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td width="11"><img src="images/PinkBorderTopLeft.jpg" alt="" width="11" height="11"></td>
                              <td class="PinkBoxTopBg"><img src="images/spacer.gif" alt="" width="10" height="11"></td>
                              <td width="11"><img src="images/PinkBorderTopRight.jpg" alt="" width="11" height="11"></td>
                            </tr>
                        </table></td>
                      </tr>
                      <tr>
                        <td class="PinkTwosideBorder" valign="top" align="center"><table width="98%" cellspacing="0" cellpadding="0" border="0" align="center">
			<TR>
				<TD align="center" class="sky font-18">My Favourite Adspaces</TD></TR>
			<TR>
			<TR>
				<TD align="right">
					<input type="button" value="Delete" id="btnDeleteFromFav" onclick="deleteFromFav();">
				</TD>
			</TR>
			
			<TR>
				<TD align="center" id="errorId">&nbsp;</TD></TR>
			<TR>
			<tr><TD>
				<table width="100%" cellspacing="0" cellpadding="0" align="center">
		
				<tr>
					<td class="sitename"><a href="#" class="headerLink">Site Name</a></td>
					<td class="product"><a href="#" class="headerLink">Product</a></td>
					<td class="rank"><a href="#" class="headerLink">Rank</a></td>
					<td class="impression"><a href="#" class="headerLink">Impression</a></td>
					<td class="click"><a href="#" class="headerLink">Click/Day</a>&nbsp;<img src="images/dwn_arrow.jpg" alt="" /></td>
					<td class="cpc"><a href="#" class="headerLink">CPC</a></td>
					<td class="price"><a href="#" class="headerLink">Min Price/Day</a></td>
				</tr>
				<?php 
				
				$i=0;
					while($result= mysql_fetch_array($query))
						{
						$i++;
						if($i%2==0)
						{
							$className = 'normalActive2';
							$className2 = 'normal2';
							$colorClass = 'gray';
						}
						else
						{
							$className = 'normalActive';
							$className2 = 'normal';
							$colorClass = 'white';
						}
							$siteUrlReplaced = str_replace("http://","",$result[adSiteUrl]);
							$siteUrlReplaceWWW = str_replace("www.","",$siteUrlReplaced);
						if($result[adspaceType]=='banner')
							$imgName = 'ban_icon.jpg';
						elseif($result[adspaceType]=='thumbnail')
							$imgName = 'thum_icon.jpg';
						else
							$imgName = 'tt_icon.gif';
						?>
							<tr id="trList<?php echo $result[favId]; ?>" onmouseover="this.className='<?php echo $className;?>'" onmouseout="checkClassName(<?php echo $result[favId]; ?>,<?php echo ($i%2); ?>);" class="<?php echo $className2; ?>" onclick="addAdSpaceId(<?php echo $result[favId]; ?>,<?php echo ($i%2); ?>);">
					<td class="<?php echo $colorClass;?>_sitename"><a href="javascript:void(0);"  onclick="location.href='adSpaceDetails.php?id=<?php echo $result[adspaceId];?>'"  class="listLink"><?php echo $siteUrlReplaceWWW; ?></a></td>

					<td class="<?php echo $colorClass;?>_product"><a href="#" class="listLink" onmouseout="hidePreview();" onmouseover="popUpPreview(<?php echo $result[adspaceId]; ?>, event, 'product');" id="balloon<?php echo $result[adspaceId]; ?>"><img src="images/<?php echo $imgName;?>" border="0" alt="" />&nbsp;<?php echo ucfirst($result[adspaceType]); ?></A>
					</td>
					
					<td class="<?php echo $colorClass;?>_rank"><?php echo getAlexaRank($siteUrlReplaced); ?></td>
					<td class="<?php echo $colorClass;?>_impression"><?php echo $result[adSiteImpression]; ?></td>
					<td class="<?php echo $colorClass;?>_click"><?php echo $result[clickPerDay]; ?></td>
					<td class="<?php echo $colorClass;?>_cpc">$<?php echo number_format($result[costPerClick], 2, '.', ''); ?></td>
					<td class="<?php echo $colorClass;?>_price"><a href="#" class="listLink" onmouseout="hidePreview();" onmouseover="popUpPreview(<?php echo $result[adspaceId]; ?>, event, 'price')">$<?php echo $result[minPrice]; ?></A>
					<div style="display:none;width:400px;z-index:1; position:absolute;background-color:ffffff;border:#CCCCCC 1px solid;" id="adpriceDiv<?php echo $result[adspaceId]; ?>"></div></td>
				</tr>
				<?php 
				$sql1="select * FROM ".ADSPSCEMASTER." where langId='".$langId."' and adspaceId='".$result[adspaceId]."'";
$query1=mysql_query($sql1);
$result1= mysql_fetch_array($query1);
$explodeDate1 = explode(' ' ,$result[publishDate]);
$siteUrlReplaced1 = str_replace("http://","",$result1[adSiteUrl]);
$siteUrlReplaceWWW1 = str_replace("www.","",$siteUrlReplaced1);

$sqlPrice="select * FROM ".PRICE." where adspaceId='".$result[adspaceId]."' order by duration asc";
$queryPrice=mysql_query($sqlPrice);
if($result[adSiteType]=='WEB')
	$adSiteType = 'Website';
else
	$adSiteType = 'Mobile';
	
#<!--###############################################################################################-->

			$GlobaLSPAce .= "spaceList[" . $result[adspaceId] . "] = ({
            'title' : '".$result1[adSpaceName]."',
            'image' : '".$GLOBALS[SiteUrl]."images/noimage.jpg',
			 'theme' : '',
            'link' : 'prompt.php?sid=f24dc7bb351fe6c1ed714721b1e632ff&url=http%3A%2F%2Fwww%2Eddlspot%2Ecom',
            'type' : 'GTB',
            'categoryPathShort' : '".$adSiteType."',
            'siteRating' : '".$result1[adsSiteRating]."',
            'urlDisplay' : '".$result1[adSiteUrl]."',
            'availableDate' : '".$explodeDate1[0]."',
                        'demographicNumber' : '6',
            'demographicDisplay' : new Array(),
            'siteDescription' : '".$result[siteDescription]."',
            'spaceDescription' : '".substr($result1[description],0,200)."',
            'spaceTags' : '".$result1[tags]."'
        });
			spaceList[" . $result[adspaceId] . "].demographicDisplay.push(new Array('Egypt', '12.51'));
			spaceList[" . $result[adspaceId] . "].demographicDisplay.push(new Array('United States', '10.86'));
			spaceList[" . $result[adspaceId] . "].demographicDisplay.push(new Array('Saudi Arabia', '9.32'));";
			
			
			$GlobaLPRIce .= "priceList[" . $result[adspaceId] . "] = new Array();";
if(mysql_num_rows($queryPrice)>0)
{
	while($resultPrice= mysql_fetch_array($queryPrice)){
	if($result[clickPerDay]==0)
	{
		$clickPerDay = '*New';
		$avgCPC = '*New';
	}
	else
	{
		$clickPerDay = $result[clickPerDay]*$resultPrice[duration];
		$avgCPC = '$'.number_format($resultPrice[ammount]/$result[clickPerDay], 2, '.', '');
	}
			$GlobaLPRIce .= "priceList[" . $result[adspaceId] . "].push({
				
				'day' : '".$resultPrice[duration]."',
				'price' : '$".$resultPrice[ammount]."',
				'avgClicks' : '".$clickPerDay."',
				'avgCostPerClick' : '".$avgCPC."'
			}); ";
	}
}
else
{
			$GlobaLPRIce .= "priceList[" . $result[adspaceId] . "].push({
				
				'day' : 'No',
				'price' : ' Found',
				'avgClicks' : ' Record',
				'avgCostPerClick' : ''
			}); ";

}


#<!--###############################################################################################-->
				}
				?>
				</table>
			</TD></TR>
			</table></td>
                      </tr>
                      <tr>
                        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td width="11"><img src="images/PinkBorderBottomLeft.jpg" alt="" width="11" height="11"></td>
                              <td class="PinkBoxBottomBg"><img src="images/spacer.gif" alt="" width="10" height="11"></td>
                              <td width="11"><img src="images/PinkBorderBottomRight.jpg" alt="" width="11" height="11"></td>
                            </tr>
                        </table></td>
                      </tr>
                    </table></td>
                    <td>&nbsp;</td>
                    </tr>
                </table></td>
              </tr>
            </table>
</div>
            
<?php
        //include("footer.php");
}
		?> 